//
//  WBWelcomeView.swift
//  Weibo
//
//  Created by 伏文东 on 2018/1/26.
//  Copyright © 2018年 伏文东. All rights reserved.
//

import UIKit
import SDWebImage

/// 欢迎视图
class WBWelcomeView: UIView {
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var tipLabel: UILabel!
    @IBOutlet weak var bottomCons: NSLayoutConstraint!
    
    
    class func welcomeView() -> WBWelcomeView {
        let wcView = Bundle.main.loadNibNamed("WBWelcomeView", owner: nil, options: nil)?.first  as! WBWelcomeView
        wcView.frame = UIScreen.main.bounds
        return wcView
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        guard let urlString = WBNetworkManager.shared.userAccount.avatar_large,
            let url = URL(string: urlString) else{ return }
        iconView.sd_setImage(with: url, placeholderImage: UIImage(named: "avatar_default_big"))
    }
    
    override func didMoveToWindow() {
        super.didMoveToWindow()
        
        bottomCons.constant = bounds.size.height - 200
        
        UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            self.layoutIfNeeded()
            self.iconView.alpha = 1
        }) { (_) in
            UIView.animate(withDuration: 1, animations: {
                self.tipLabel.alpha = 1
            }) { (_) in
                self.removeFromSuperview()
            }
        }
    }
        
}
